// 页面白名单
const whiteList = [
    '/',
    '/pages/login/login',
    '/pages/index/index',
]
const isInterceptor = false
const list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]

function hasPermission (url) {
    // 在白名单中或有token，直接跳转
    if(whiteList.indexOf(url) !== -1) {
        return true
    }
    return false
}

list.forEach((item) => {
	uni.addInterceptor(item, {
		// 页面跳转前进行拦截, invoke根据返回值进行判断是否继续执行跳转

		invoke(e) {
			if (!hasPermission(e.url) && isInterceptor) {
				
				uni.navigateTo({
					url: "/pages/login/login",
				});
				
				return false;
			}
			return true;
		}
	});
})